
/**
 * [getPrinterName 获取所有打印机数据]
 * @param  {[type]}  defaultPrint [默认打印机名称]
 * @param  {Boolean} isIndex      [是否打印机索引值]
 * @return {[type]}               [description]
 */
function getPrinterName(LODOPOBJ, defaultPrint , isIndex) {
    var options = "";       // 打印机选项
    var COUNT = LODOPOBJ.GET_PRINTER_COUNT();
    for (var i = 0; i < COUNT; i++) {
        var printerName = LODOPOBJ.GET_PRINTER_NAME(i);
        var selected = "";
        if (defaultPrint == printerName) {
            selected = " selected";
        }
        if(isIndex){
            options += "<option value='" + i + "' " + selected + ">" + printerName + "</option>";
        }else{
            options += "<option value='" + printerName + "' " + selected + ">" + printerName + "</option>";
        }
    }
    return options;
}



/* -----------------------------------------------连号操作相关工具函数------------------------------------------------------------------------------------------------------ */

/**
 * 字串相关 String
 */
/** 修剪字串前后的空格 Base 20030820 */
function Trim(str) {
    return LTrim(RTrim(str));
}

function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ")
            break;
    }
    str = str.substring(i, str.length);
    return str;
}

function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " ")
            break;
    }
    str = str.substring(0, i + 1);
    return str;
}
//取消左右空格
String.prototype.trim = function () {
    return this.replace(/(^\s*)  |(\s*$)/g, "");
}
/** 测量有汉字时的字串实际长度，其中一个汉字占两个字符 Base 20030820 */
function len(s) {
    var length = 0;
    var tmpArr = s.split("");
    for (i = 0; i < tmpArr.length; i++) {
        if (tmpArr[i].charCodeAt(0) < 299)
            length++;
        else
            length += 2;
    }
    return length;
}

/** 是否为合法字串，指只包括字母，数字和_的字串　*/
function isStr(s) {
    if (s.length == 0)
        return false;
    var regu = "^[0-9A-Za-z_]*$";
    var re = new RegExp(regu);
    if (s.search(re) != -1)
        return true;
    else {
        return false;
    }
}

/** 判断日期 */
function isDate(str) {
    return (str + " 00:00:00").checkTime();
}

/** 判断时间 */
function isTime(str) {
    return (str).checkTime();
}

String.prototype.checkTime = function () {
    var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
    if (r == null)
        return false;
    var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
    return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
}

/**
 * 数字相关
 */
/** 是否为数字 Base 20030821 */
// isNaN 判断是否是数字（包括小数）
function isNum(s) {
    if (s == null)
        return false;
    var regu = "^([0-9]*)$";
    var re = new RegExp(regu);
    if (s.search(re) != -1)
        return true;
    else
        return false;
}

//LEFT，RIGHT，MID函数
function Left(mainStr, lngLen) {
    if (lngLen > 0) {
        return mainStr.substring(0, lngLen);
    } else {
        return null;
    }
}

function Right(mainStr, lngLen) {
    if (mainStr.length - lngLen >= 0 && mainStr.length >= 0 && mainStr.length - lngLen <= mainStr.length) {
        return mainStr.substring(mainStr.length - lngLen, mainStr.length);
    } else {
        return null;
    }
}

function Mid(mainStr, starnum, lngLen) {
    if (mainStr.length >= 0) {
        return mainStr.substr(starnum, lngLen);
    } else {
        return null;
    }
}

/**
 * 获取快递号验证码
 * Exp_Num     累加后的数字
 * p_Exp_Num   上一个快递单号(完整的，针对顺丰、宅急送有用)
 */
function get_Exp_Num_No(Exp_Num, Exp_Name, p_Exp_Num) {
    Exp_Num = Exp_Num.toString();
    var Exp_Num_Length = Exp_Num.length;
    var p_Exp_Num_Length = p_Exp_Num.length;
    var Num_No = "";

    if (Exp_Name.toUpperCase().indexOf("EMS") >= 0 || Exp_Name.toUpperCase().indexOf("E邮宝") >= 0) {
        //EMS必须是8位数字进行校验，包括最开始的0，长度不足有可能是开始位置的0被截取了，详看Ck_Admin/Print_Pro_Order_List.aspx页面 Exp_Name.toUpperCase().indexOf("邮政国内") >= 0
        for (var i = 0; i < 8 - Exp_Num_Length; i++) {
            Exp_Num = "0" + Exp_Num;
        }
        var num1 = Mid(Exp_Num, 0, 1);
        var num2 = Mid(Exp_Num, 1, 1);
        var num3 = Mid(Exp_Num, 2, 1);
        var num4 = Mid(Exp_Num, 3, 1);
        var num5 = Mid(Exp_Num, 4, 1);
        var num6 = Mid(Exp_Num, 5, 1);
        var num7 = Mid(Exp_Num, 6, 1);
        var num8 = Mid(Exp_Num, 7, 1);

        //EMS规则
        Num_No = (8 * num1 + 6 * num2 + 4 * num3 + 2 * num4 + 3 * num5 + 5 * num6 + 9 * num7 + 7 * num8);
        Num_No = 11 - (Num_No) % (11);
        if (Num_No == 10)
            Num_No = 0;
        if (Num_No == 11)
            Num_No = 5;
    }

    if (Exp_Name.toUpperCase().indexOf("顺丰") >= 0) {
        //保证长度12
        for (var i = 0; i < 12 - p_Exp_Num_Length; i++) {
            p_Exp_Num = "0" + p_Exp_Num;
        }
        var num1 = Mid(p_Exp_Num, 0, 1);
        var num2 = Mid(p_Exp_Num, 1, 1);
        var num3 = Mid(p_Exp_Num, 2, 1);
        var num4 = Mid(p_Exp_Num, 3, 1);
        var num5 = Mid(p_Exp_Num, 4, 1);
        var num6 = Mid(p_Exp_Num, 5, 1);
        var num7 = Mid(p_Exp_Num, 6, 1);
        var num8 = Mid(p_Exp_Num, 7, 1);
        var num9 = Mid(p_Exp_Num, 8, 1);
        var num10 = Mid(p_Exp_Num, 9, 1);
        var num11 = Mid(p_Exp_Num, 10, 1);
        var num12 = Mid(p_Exp_Num, 11, 1);

        //保证长度11
        for (var i = 0; i < 11 - Exp_Num_Length; i++) {
            Exp_Num = "0" + Exp_Num;
        }
        var Nnum1 = Mid(Exp_Num, 0, 1);
        var Nnum2 = Mid(Exp_Num, 1, 1);
        var Nnum3 = Mid(Exp_Num, 2, 1);
        var Nnum4 = Mid(Exp_Num, 3, 1);
        var Nnum5 = Mid(Exp_Num, 4, 1);
        var Nnum6 = Mid(Exp_Num, 5, 1);
        var Nnum7 = Mid(Exp_Num, 6, 1);
        var Nnum8 = Mid(Exp_Num, 7, 1);
        var Nnum9 = Mid(Exp_Num, 8, 1);
        var Nnum10 = Mid(Exp_Num, 9, 1);
        var Nnum11 = Mid(Exp_Num, 10, 1);
        var Nnum12 = 0;

        //顺丰规则
        if (Nnum9 - num9 == 1 && num9 % 2 == 1) {
            if (num12 - 8 >= 0) {
                Nnum12 = num12 - 8;
            } else {
                Nnum12 = num12 - 8 + 10;
            }
        } else if (Nnum9 - num9 == 1 && num9 % 2 == 0) {
            if (num12 - 7 >= 0) {
                Nnum12 = num12 - 7;
            } else {
                Nnum12 = num12 - 7 + 10;
            }
        } else {
            if ((num10 == 3 || num10 == 6) && num11 == 9) {
                if (num12 - 5 >= 0) {
                    Nnum12 = num12 - 5;
                } else {
                    Nnum12 = num12 - 5 + 10;
                }
            } else if (num11 == 9) {
                if (num12 - 4 >= 0) {
                    Nnum12 = num12 - 4;
                } else {
                    Nnum12 = num12 - 4 + 10;
                }
            } else {
                if (num12 - 1 >= 0) {
                    Nnum12 = num12 - 1;
                } else {
                    Nnum12 = num12 - 1 + 10;
                }
            }
        }
        Num_No = Nnum12;
    }
    if (Exp_Name.toUpperCase().indexOf("联邦") >= 0) {
        //联邦规则
        if (parseInt(Exp_Num) % 11 == 10) {
            Num_No = 0;
        }
        else {
            Num_No = parseInt(Exp_Num) % 11;
        }
    }
    if (Exp_Name.toUpperCase().indexOf("星晨") >= 0 || Exp_Name.toUpperCase().indexOf("宅急送") >= 0) {
        //规则：最后一个数字是从0递增至6，到6后，再返回0开始递增至6；
        //保证长度10
        for (var i = 0; i < 10 - p_Exp_Num_Length; i++) {
            p_Exp_Num = "0" + p_Exp_Num;
        }
        var num10 = Mid(p_Exp_Num, 9, 1);
        if (num10 < 6) {
            Num_No = num10 * 1 + 1;
            //注意乘以1，转化为数字+1
        } else {
            Num_No = 0;
        }
    }
    return Num_No.toString();
}